<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h1>网页在<span>5</span>秒后跳转到攀枝花学院！</h1>
		<button onclick="f1()">停止跳转</button>
		<script type="text/javascript">
			function f2(){
				location.href="https://www.pzhu.edu.cn/"
			}
			
			function f3(){//可视的数字变化倒计时
				let span=document.querySelector("h1>span")
				if(span.innerHTML>1)//不出现0数字计时
				span.innerHTML=span.innerHTML-1
			}
			
			//下述代码只能控制停止
			// function f1(){
			// 	clearTimeout(t1)
			// 	clearInterval(t2)
			// }
			
			let t1=setTimeout(f2,5000)//接收
			let t2= setInterval(f3,1000)
			
			let state=true//定时器默认运行中
			function f1(){
				if(state){
					clearTimeout(t1)
					clearInterval(t2)
					document.querySelector("button").innerHTML="继续跳转"
					state=false
				}else{
					t1=setTimeout(f2,document.querySelector("h1>span").innerHTML*1000)
					t2=setInterval(f3,1000)
					document.querySelector("button").innerHTML="停止跳转"
					state=true
				}
			}
			
		</script>
	</body>
</html>
